package com.cn.demo4.servlet;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/outLogin")
public class OutLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //得到当前用户的session
        HttpSession session = req.getSession();
        if (session != null) {
            // 2.删除属性
            session.removeAttribute("loginPhone");

        }
        // 2.返回登录页面P
        resp.sendRedirect(req.getContextPath() + "/html/login.html");
//        req.getRequestDispatcher("/html/login.html").forward(req,resp);//页面转发，转发数据
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
//    public static Boolean outLogin(HttpServletRequest req, HttpServletResponse resp){
//        //得到当前用户的session
//        HttpSession session = req.getSession();
//        if (session != null){
//            session.removeAttribute("phone");
//            return true;
//        }
//        return false;
//    }
}

